package com.tianhua.javs.core.func.script.business;

import com.tianhua.javs.client.bean.*;
import com.tianhua.javs.client.func.IBusinessTranslatorFunc;
import com.tianhua.javs.core.func.TranslatorContainer;
import com.tianhua.javs.core.func.script.IBusinessFunc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Description:对业务关键字bo进行解析
 * date: 2022/2/12
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Component(value = "boFunc")
public class BOFunc implements IBusinessFunc {
    @Autowired
    private TranslatorContainer translatorContainer;

    @Override
    public TranslateResultBean translate(JavsTranslateContextBean javsTranslateContextBean, String keyWardStr, Map<String, JavsParamBean> javsVarMap) {

        JavsSegmentBean javsSegmentBean = null;
        Component component = BOFunc.class.getAnnotation(Component.class);
        List<IBusinessTranslatorFunc> translatorFuncList = translatorContainer.getByBusinessScriptFuncBean(component.value());
        for (IBusinessTranslatorFunc translatorFunc : translatorFuncList) {
            javsSegmentBean = translatorFunc.translate(keyWardStr,javsVarMap);
            //如果函数匹配到则不再进行后续的匹配内容
            if(javsSegmentBean != null && javsSegmentBean.match()){
                //收集需要导入的包
                javsTranslateContextBean.getCurrentScriptMethodBean().addPackageList(javsSegmentBean.getPackageList());
                break;
            }
        }
        return TranslateResultBean.getInstance(javsSegmentBean);
    }

}
